#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QWidget>
#include <QObject>
#include<QToolBar>
#include<QToolButton>
#include <QDate>
#include <QThread>
#include <QVector>
#include <QTimer>

#include "api/api.h"
//#include"bll/sqlitethread.h"
#include"tcpclient.h"
#include"outwork.h"
#include"mylistwidget.h"
#include"mywidget.h"

#include"mygradetablewidget.h"
#include"mycodesetwidget.h"
#include"checkcodewidget.h"
#include"mypeopleinfo.h"
#include"mypeoplewidget.h"
#include"changeidwidget.h"
#include "upordown.h"
//#include "trueapi.h"


QT_BEGIN_NAMESPACE
class QLineEdit;
class QToolBar;
class QToolButton;
class QTcpSocket;
class QTimer;
QT_END_NAMESPACE

class MyListWidget;
class InWork;
class OutWork;
class MyWidget;
class MyGradeTableWidget;
class MyCodeSetWidget;
class CheckCodeWidget;
class MyPeopleWidget;
class MyPeopleInfo;
class ChangeIdWidget;

class MainWindow : public QWidget
{
  Q_OBJECT
public:
  explicit MainWindow(QWidget *parent = nullptr);
  ~MainWindow();

  void create();

  void startSocket();

  void startTimer();

//  bool runMain();

//  void stopMain();

  void startThread();

  void initConnect();

public:

  //发送数据
  void sendData(const QByteArray& msg);

//  QString getMyIpString();

  //定时器
public:

  //人员信息录入
//  bool readCard();

  bool deleteFile(const QString &strPath);

  void readText();

  //人员信息绑定
  //  void bindInfo(const QString& name,const QString& idCard);

  void closeSocket();


public slots:


  void clearAll();

  void clearonly_clicked();

  void codeset_clicked();

  void calib_clicked();

  void people_clicked();

//  void info_clicked();

  void grade_clicked();

  void changeid_clicked();

  void close_clicked();

  void upORdown_clicked();

  //地址设置 原新编码控制信息
  void sendYuanXin(int old_addr,int new_addr);

  //双击打开详细界面
  void doubleClicked(int msg);

  //校准程序 开始校准控制信息
  void sendBegin(int flag);

  //校准程序 结束控制信息
  void sendOver(int flag);

  //成绩导出 查询成绩控制信息
  void sendSearchData(int fenZu,int baHao,const QString& time);
  //传递日期
  void sendDateChande(QString time);
  //传递靶号和组号
  void sendAddrAndGroupnumber(int addr,int groupnumber);

  //人员分组控制信息
  void sendGroupNumber(const QString& indexZuHao);

  void sendCheckXandY(int addr,int x,int y);

  void sendUporDown(int code);

  void infoOpen();

  void infoClose();

//  void checkSlot();

  //更改系统id
    void changeId(const QString& str);

  //  void updateState(const QList<int>& vec);
  //  void showInfo(const QString& data);

  void onDisconnected();

  void onConnected();

  void reconnect();


signals:


private:

    Api *api=nullptr;

  MyListWidget *myListWidget = nullptr;

  QToolBar *toolBar = nullptr;

  QToolButton *act[10];

  TcpClient *tcpClient = nullptr;

  OutWork *outWork = nullptr;

//  SQLiteThread *sqliteThread = nullptr;


  MyWidget *myWidget = nullptr;

  MyGradeTableWidget *myGradeTableWidget = nullptr;

  MyCodeSetWidget *myCodeSetWidget = nullptr;

  CheckCodeWidget *checkCodeWidget = nullptr;

  MyPeopleWidget *myPeopleWidget = nullptr;

  MyPeopleInfo *myPeopleInfo = nullptr;

  ChangeIdWidget *changeIdWidget = nullptr;

  UporDown *upDown = nullptr;

private:

  QList<int> vecState;

  QDate m_date;
  QString currentDate;

  QThread  *threadOne = nullptr;
  QThread *threadTwo = nullptr;

  QVector<QString> vecIdCard;

  QTimer battery_Timer;

    QTimer state_Timer;


private:

  //分组信息 默认为-1
  int group_number = 1;

  int s_group = 1;

  //当前id
  int s_index = -1;

  //记录当前id 与上次id 用于复位
  int index2 = 1;
  int index3 = -2;

  //屏幕宽度
  double nWidth;
  double nHeight;


  QTcpSocket *m_socket = nullptr;

  QTimer m_reconnectTimer;

};

#endif // MAINWINDOW_H
